<?php

namespace App\Http\Controllers\user;

use App\Engine\BaseController;
use App\Engine\TokenService;
use App\Models\Collection as CollectionModel;
use function app\Utils\go;

class Collection extends BaseController
{
    public function get()
    {
        $res=CollectionModel::with('house')->where('uid',TokenService::getCurrentUid())->get();
        return go($res);
    }

    public function insert()
    {
        $where=[
            'hid'=>$this->get['id'],
            'uid'=>TokenService::getCurrentUid()
        ];
        $collection=CollectionModel::where($where)->first();
        if($collection)
            $res=$collection->delete();
        else
            $res=CollectionModel::create(['uid'=>TokenService::getCurrentUid(),'hid'=>$this->get['id']]);
        return go($res);
    }
}
